package org.neuedu.ssmp.crm.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.*;
import org.neuedu.ssmp.crm.entity.Chances;
import org.neuedu.ssmp.crm.entity.Customer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author MoonHolder
 * @since 2019-12-09
 */
public interface CustomerMapper extends BaseMapper<Customer> {
    @Results({
            @Result(property = "levelId", column = "level_id"),
            @Result(property = "levelName", column = "level_id", one = @One(select = "org.neuedu.ssmp.crm.mapper.CustomerMapper.findCustomerLevel"))
    })
    @Select("select id, name, code, user_id, area_id, level_id, manager_name, agree_level, credit_level, address, postcode, phone, fax, website, bussiness_code, regs_money, reg_bank, landtax_code, legal_person, bussiness_money, bank_account, nationaltax_code, is_lost, is_del from customer ${ew.customSqlSegment}")
    IPage<Customer> conditionPage(IPage<Customer> page, @Param(Constants.WRAPPER) Wrapper<Customer> wrapper);

    @Select("select name from customer_level where id = #{levelId};")
    String findCustomerLevel(int levelId);

    @Insert("insert into customer (name,code,user_id,manager_name) values (#{name},#{code},#{id},#{username})")
    boolean inserts(String name,String code,Integer id,String username);
}
